package de.fhaugsburg.games.boardgames.tests;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import de.fhaugsburg.games.boardgames.Board;
import de.fhaugsburg.games.boardgames.Piece;
import de.fhaugsburg.games.boardgames.exceptions.GameException;

public class BoardTest {
	private Board board1;
	private Piece piece1;

	@Before
	public void setUp() throws Exception {
		board1 = new Board(8, 7); // create a board with 8 rows and 7 columns
		piece1 = Piece.O;
		board1.putPiece(piece1, 2, 2); // put the piece "O" on the field in the
		// second row,second column
	}

	@Test
	public void testPutPiece() throws GameException {
		board1.putPiece(piece1, 1, 1); // check if the method throws a
										// nullpointer exception
	}

	@Test
	public void testGetPiece() {
		assertEquals(piece1, board1.getPiece(2, 2));
	}

	@Test
	public void testIsEmpty() {
		assertEquals(null, board1.getPiece(1, 1));
	}

	@Test
	public void testGetHeight() {
		assertEquals(8, board1.getHeight());
	}

	@Test
	public void testGetWidth() {
		assertEquals(7, board1.getWidth());
	}

	@Test
	public void testIsOnTheBoard() {
		assertTrue(board1.isOnTheBoard(4, 4));
		assertTrue(!board1.isOnTheBoard(9, 9));
	}

	@Test
	public void testRemovePiece() throws GameException {
		assertEquals(piece1, board1.removePiece(2, 2));
		assertTrue(board1.isEmpty(2, 2));
	}

	@Test
	public void testMovePiece() throws GameException {
		board1.movePiece(2, 2, 3, 3);
		assertTrue(board1.isEmpty(2, 2));
		assertEquals(piece1, board1.getPiece(3, 3));
	}

	@Test
	public void testReset() throws GameException {
		board1.reset();
		assertTrue(board1.isEmpty(2, 2));
	}

}
